package com.example.checkqufuface.Customer;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.checkqufuface.Adapter.TicketStatueBackResultAdapter;
import com.example.checkqufuface.Adapter.TicketStatueCheckResultAdapter;
import com.example.checkqufuface.Adapter.TicketStatueResultAdapter;
import com.example.checkqufuface.R;
import com.example.checkqufuface.bean.CheckShowBaseBean;
import com.example.checkqufuface.bean.QufuQueryTicketCheckResultBean;

import java.util.ArrayList;
import java.util.List;

public class BottomTicketAndReturnDialog extends BottomDialogBase implements View.OnClickListener {

    private Context context;
    private ImageView close;
    private TextView tvTack;
    private RecyclerView rvTack;
    private TextView tvBack;
    private RecyclerView rvBack;
    private TextView tvCheck;
    private RecyclerView rvCheck;

    // 检票，退票，取票
    public BottomTicketAndReturnDialog(Context context, List<QufuQueryTicketCheckResultBean.DataBean.CheckResultListBean> checkResultList,
                                       List<QufuQueryTicketCheckResultBean.DataBean.ReturnResultListBean> returnResultList,
                                       List<QufuQueryTicketCheckResultBean.DataBean.TackResultListBean> tackResultList) {
        super(context);
        this.context = context;

        //--------------------------------------------------------
        if (checkResultList.size() > 0) {
            tvCheck.setVisibility(View.VISIBLE);
            rvCheck.setVisibility(View.VISIBLE);

            List<CheckShowBaseBean> baseBeanList = new ArrayList<>();
            //重新构建集合
            for (int i = 0; i < checkResultList.size(); i++) {
                CheckShowBaseBean checkShowBaseBean = new CheckShowBaseBean();
                checkShowBaseBean.setUserName(checkResultList.get(i).getUserName());
                checkShowBaseBean.setAmount(checkResultList.get(i).getAmount());
                checkShowBaseBean.setCreatedDate(checkResultList.get(i).getCreatedDate());
                checkShowBaseBean.setTerminalName(checkResultList.get(i).getTerminalName());

                baseBeanList.add(checkShowBaseBean);
            }

            TicketStatueCheckResultAdapter ticketStatueResultAdapter = new TicketStatueCheckResultAdapter(context, baseBeanList);
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
            rvCheck.setLayoutManager(linearLayoutManager);
            rvCheck.setAdapter(ticketStatueResultAdapter);

        } else {
            tvCheck.setVisibility(View.GONE);
            rvCheck.setVisibility(View.GONE);
        }

        //---------------------------------------
        if (returnResultList.size() > 0) {

            List<CheckShowBaseBean> baseBeanList = new ArrayList<>();
            //重新构建集合
            for (int i = 0; i < returnResultList.size(); i++) {
                CheckShowBaseBean checkShowBaseBean = new CheckShowBaseBean();
                checkShowBaseBean.setUserName(returnResultList.get(i).getUserName());
                checkShowBaseBean.setAmount(returnResultList.get(i).getAmount());
                checkShowBaseBean.setCreatedDate(returnResultList.get(i).getCreatedDate());
                checkShowBaseBean.setTerminalName(returnResultList.get(i).getTerminalName());

                baseBeanList.add(checkShowBaseBean);
            }

            TicketStatueBackResultAdapter ticketStatueResultAdapter = new TicketStatueBackResultAdapter(context, baseBeanList);
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
            rvBack.setLayoutManager(linearLayoutManager);
            rvBack.setAdapter(ticketStatueResultAdapter);

            tvBack.setVisibility(View.VISIBLE);
            rvBack.setVisibility(View.VISIBLE);
        } else {
            tvBack.setVisibility(View.GONE);
            rvBack.setVisibility(View.GONE);
        }


        //---------------------------------------------------
        if (tackResultList.size() > 0) {

            List<CheckShowBaseBean> baseBeanList = new ArrayList<>();
            //重新构建集合
            for (int i = 0; i < tackResultList.size(); i++) {
                CheckShowBaseBean checkShowBaseBean = new CheckShowBaseBean();
                checkShowBaseBean.setUserName(tackResultList.get(i).getUserName());
                checkShowBaseBean.setAmount(tackResultList.get(i).getAmount());
                checkShowBaseBean.setCreatedDate(tackResultList.get(i).getCreatedDate());
                checkShowBaseBean.setTerminalName(tackResultList.get(i).getTerminalName());

                baseBeanList.add(checkShowBaseBean);
            }

            TicketStatueResultAdapter ticketStatueResultAdapter = new TicketStatueResultAdapter(context, baseBeanList);
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
            rvTack.setLayoutManager(linearLayoutManager);
            rvTack.setAdapter(ticketStatueResultAdapter);

            tvTack.setVisibility(View.VISIBLE);
            rvTack.setVisibility(View.VISIBLE);
        } else {
            tvTack.setVisibility(View.GONE);
            rvTack.setVisibility(View.GONE);
        }


        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }


    @Override
    protected void onCreate() {
        setContentView(R.layout.widget_ticket_back_return);

        tvTack = findViewById(R.id.tv_tack);
        rvTack = findViewById(R.id.rv_ticket_take);

        tvBack = findViewById(R.id.tv_back);
        rvBack = findViewById(R.id.rv_ticket_back);

        tvCheck = findViewById(R.id.tv_check);
        rvCheck = findViewById(R.id.rv_ticket_check);

        close = findViewById(R.id.iv_wg_qu_xiao_ka);


    }

    @Override
    public void onClick(View v) {
        dismiss();
    }

}


